<include file="Common:pony" />
<body>
<include file="Common:sellerpanel" />
<h2>已发货订单</h2>
<form method="post" id="tradeSearch" name="tradeSearch"  action="<{:U('tradesearch')}>">
<table width="100%" cellspacing="1" cellpadding="3" border="0">
<tr>
	<td>搜索订单</td>
	<td>
		<select name="field" id="field">
		<option value="receiver_name">收货人姓名</option>
		<option value="buyer_nick">买家昵称</option>
		<option value="receiver_mobile">收货人的手机号码</option> 	
		<option value="receiver_phone">收货人的电话号码</option>
		<option value="tplid">快递模板</option>
		</select>
		
		<input type="text" id="k" name="k" value="<{$map[k]}>">
		<select name="tplid" id="tplid" style="display:none"><option value="0">选择快递</option><{$tploptions}></select>
		
		<input type="hidden" name="status" id="status" value="<{$status}>" />
		<input type="submit" name="submit" id="submit" value="搜索" />
	</td>
	<td>
	</td>
</tr>
</table>
</form>

<form id="form1" name="form1" method="post" action="<{:U('tradesendall')}>">
<table width="100%" cellspacing="1" cellpadding="3" border="0">
<tr>
	<td width="10%">
		<input type="submit" name="submit" id="btnAllTradeSend" value=" 批量发货 " />
	</td>
	<td><span style="font-family: 微软雅黑, Tahoma; letter-spacing: 2px; display: none;" id="result"></span>
	</td>
</tr>
</table>
<table width="100%" cellspacing="1" cellpadding="3" border="0">
<tr class="header">
<th width="50" height="30" align="center"><input type="checkbox" name="tidall" id="tidall"><label for="tidall">全选</label></th>
<th width="100" height="30">订单号</th>
<th>买家帐号</th>
<th>收货地址</th>
<th width="120">卖家备注<br>
  买家留言</th>
<th width="130">商品信息</th>
<th width="100" align="center">快递</th>
<th align="center">运单号</th>
<th align="center">订单金额<br>
  总成本</th>
<th align="center">提交时间</th>
<th align="center">卖家发货</th>
<th width="70" align="center">待处理</th>
</tr>
<php>
if( $tradelist ) {
	
	foreach( $tradelist as $trade ) {
		$ordersinfo = '';
		$orders = unserialize( $trade['orders'] );		
		foreach(  $orders['order'] as $t=>$order ){
			$ordersinfo .= '<div>'. ($t+1).'.'. $order['outer_sku_id'] .'('.$order['num'] .'件)</div>';
		} 
		$company = D('Company')->where("id={$trade['syscomid']}")->getField('name');
		$tradeflag = tradeflag( $trade['seller_flag'] );
		$tradefeedback = D('Tradefeedback')->where("tid={$trade['tid']}")->find();
		echo '<tr class="row">';
		if($trade[status] == 'WAIT_SELLER_SEND_GOODS' ) {
			echo '<td height="50" align="center"><input type="checkbox" name="tid[]" id="tid_'. number_format( $trade['tid'], 0, '', '' ) . '" value="'. number_format( $trade['tid'], 0, '', '' ) . '" /></td>';
		}else {
			echo '<td height="50" align="center"> - </td>';
		}
		echo '<td height="50">'. strval($trade['tid']). '</td>
		<td>'. $trade['buyer_nick'] .'<br>'. contacttuser( $trade['buyer_nick'] ) . '</td>
		<td>'. $trade['receiver_name'] .','. $trade['receiver_mobile'] . ','. $trade['receiver_phone'] .',<br>' . $trade['receiver_state'] .', '. $trade['receiver_city']. ' '. $trade['receiver_district'] .','. $trade['receiver_address'] .','. $trade['receiver_zip'] . '</td>
		<td align="center"><span style="color:red">'. $tradeflag . ' '. $trade['seller_memo'] . '</span><br><span style="color:blue">' . $trade['buyer_message'] .'</span></td>
		<td>'. $ordersinfo .'</td>
		<td align="center">'. $company .'</td>
		<td align="center">'. $trade['out_sid'] .'</td>
		<td align="center">' .$trade['payment']. '/'. $trade['syscost'] .' </td>
		<td align="center">' .$trade['sysaddtime'] .' </td>';
		//WAIT_SELLER_SEND_GOODS 等待卖家发货
		if($trade[status] == 'WAIT_SELLER_SEND_GOODS' ) {
			echo '<td><input type="button" id="btnTradeSend_'.$trade['tid'].'" alt="'.$trade['tid'].'" value="发货" /></td>';
		}else {
			echo '<td> √ </td>';
		}
		echo '<td align="center" width="70">';
		if( $tradefeedback  ) {
			echo '<img src="'. __PUBLIC__. '/images/talk_on.png" id="toTalk_'. strval($trade['tid']) .'" style="cursor:pointer" alt="'. strval($trade['tid']) .'" title="'. U("Index/tradefeedback?tid={$trade['tid']}") .'" />';
		} else {
			echo '<img src="'. __PUBLIC__. '/images/talk_off.png" id="toTalk_'. strval($trade['tid']) .'" style="cursor:pointer" alt="'. strval($trade['tid']) .'" title="'. U("Index/tradefeedback?tid={$trade['tid']}") .'" />';
		}
		echo '&nbsp;&nbsp;';
		if( $trade[systodo] ) {
			echo '<img src="'. __PUBLIC__. '/images/do_on.png" id="todo_'. strval($trade['tid']) .'" style="cursor:pointer"  alt="'. strval($trade['tid']) .'" />';
		}else {
			echo '<img src="'. __PUBLIC__. '/images/do_off.png" id="todo_'. strval($trade['tid']) .'" style="cursor:pointer" alt="'. strval($trade['tid']) .'" />';
		}
		echo '</td></tr>';
	} 
}
////	[<a href="' .U("Index/tradefeedback?tid={$trade['tid']}"). '">查看内容</a>]
////	 <input type="button" id="btnCanceltodo_' .strval($trade['tid']) . '" name="btnCanceltodo_' .strval($trade['tid']) . '" alt="'. strval($trade['tid']) .'"  value="取消处理" />


//// <input type="button" value="待处理" name="todo_' .strval($trade['tid']) . '" id="todo_' .strval($trade['tid']) . '" alt="' .strval($trade['tid']) . '">			
</php>
<tr>
<td colspan="11" height="30" align="center"><div><{$page}></div></td>
</tr>
</table>
</form>
<script>
$(document).ready(function(){
	$("select[id^='company_']").bind('change', function(){
		var tplid = $(this).val();
		var tid   = $(this).attr( 'alt' );
		$.post ( '<{:U('Index/price')}>', { trade : $("#tradedata_" + tid ).val() , tplid: tplid }  ,
			function(data){
				if( 1 == data['status'] ) {
					$('#chengben_'+tid).html( data['data']['cost'] );	
				} else {
					alert( data['info']);
				}
			 	
			}	
		); 
	});
	
	
	$("img[id^='todo_']").bind( 'click', function() {
		var tid = $(this).attr( 'alt' );
		var _this  = $(this);
		$.post( '<{:U('Index/tradetodo')}>' , {
			tid : tid
		}, 
		function(data){
			if( 1 == data['status'] ){
				if( 1 == data['data'] ) {
					_this.get(0).src ='<{:__PUBLIC__}>/images/do_on.png';
				}else {
					_this.get(0).src ='<{:__PUBLIC__}>/images/do_off.png';
				}
				//alert( data['info'] );
				//_this.attr('disabled', 'disabled');
			}else {
				alert('提交失败 '+ data['info'] );	
			}
			
		} 
	);
	} );
	
	$("img[id^='toTalk_']").bind( 'click', function(){
		
		var _this = $(this);
		var tid = _this.attr('alt');
		var url = _this.attr('title');
		
		art.dialog.open( url , {
			id: 'fedbbackID',
		    title: '待处理',
		    yesFn: function(){
		    },
		    noFn: function(){
		    }
		});
		
	} )
	
	$("input[id^='btnCanceltodo_']").bind('click', function(){
		var tid = $(this).attr( 'alt' );
		if(window.confirm('真的要取消处理？')){
			$.post('<{:U('Index/tradefeedbackcancel')}>' , {
				tid : tid
				
			} , function(data){
				if( 1 == data['status'] ){
					alert( data['info'] );
				}else {
					alert('提交失败 '+ data['info'] );	
				}
			} );
			
		}
		
	});
	
	
	
	//搜索
	$("#field").val( '<{$map[field]}>' );
	if(  $("#field").val() == 'tplid' ){
		$("#tplid").show();	
		$("#k").hide();
		
		$("#tplid").val( <{$map[tplid]}> );
	}else {
		$("#tplid").hide();
		$("#k").show();
	}
	
	$("#field").bind("change", function(){
		if( $(this).val() == 'tplid' ){
			$("#tplid").show();	
			$("#k").hide();
		}else {
			$("#tplid").hide();
			$("#k").show();
		}
		
		
	});
	
	//发货
	$("input[id^='btnTradeSend_']").bind('click', function(){
		var tid = $(this).attr( 'alt' );
		var _this = $(this);
		$.post( '<{:U('Index/tradesend')}>' , {
				//tid : tid, company_code: company_code ,  out_sid : out_sid 
				tid : tid
			}, 
			function(data){
				if( 1 == data['status'] ){
					//alert( data['info'] );
					_this.val('已发货').attr('disabled', 'disabled');
				}else {
					//alert('提交失败 '+ data['info'] );	
				}
				
			} 
		);
	} );
	
	
	
	//全选
	$(":checkbox[id^=tid_]").click( function() {
		chcekstyle( $(this) ); 
		
	} );
	function chcekstyle ( $checkbox ) {
		var tr = $checkbox.parent().parent();
		var checked = $checkbox.attr("checked");
		if( checked ) {
			tr.css('background', '#CCFFCC');
		}else {
			tr.css('background', '');
		}
		
	}
	$("#tidall").click( function () {
		$(":checkbox[id^=tid_]").attr("checked", $(this).attr("checked") );
		$(":checkbox[id^=tid_]").each( function( i ){
			chcekstyle( $(this) ); 
			
		} );
	} );
	
	
	
	//批量发货
	$('#form1').ajaxForm({
		beforeSubmit : checkForm, // pre-submit callback
		success : complete, // post-submit callback
		dataType : 'json'
	});
	function checkForm() {
		
		var error = '';
		var tids = $(":input[id^='tid_']:checked");
		 
		if( tids.length == 0 ) { 
			error = '订单未选择';
		}
		 
		if( error != '' ) {
			$('#result').html( error ).show().fadeOut(2000);
			$("#btnAllTradeSend").removeAttr( "disabled" ).val(" 批量发货 ");
			return false;
		}else{
			$("#btnAllTradeSend").attr( "disabled" , "disabled").val(" 正在批量发货... ");
		}
		//可以在此添加其它判断	
	}
	function complete(data) {
		if (data.status == 1) {
			$('#result').html(data.info).show();
			var tids = data.data;
			if( tids ) {
				var tidsarr = tids.split(',');
				for( var i =0; i< tidsarr.length ; i++ ) {
					$("#btnTradeSend_"+ tidsarr[i]).replaceWith( "√" );	//不能点击
					$("#tid_"+ tidsarr[i]).replaceWith( "-" );						//取消选中
				}
			}
			
		} else {
			$('#result').html(data.info).show();
		}
		$("#btnAllTradeSend").removeAttr( "disabled" ).val(" 批量发货 ");
	}
	
	
	
});
</script>
</body>
</html>